package com.zhihuishu.micro.course.openapi.cc.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

import com.able.openapi.createCourse.IOnlineExamForCreateCourseService;
import com.able.openapi.createCourse.dto.ExamCourseDto;
import com.google.common.collect.Lists;
import com.zhihuishu.micro.course.constant.CourseModeConstant;
import com.zhihuishu.micro.course.dto.ChapterDto;
import com.zhihuishu.micro.course.dto.CourseCategoryDto;
import com.zhihuishu.micro.course.dto.CourseClipsDto;
import com.zhihuishu.micro.course.dto.CourseDto;
import com.zhihuishu.micro.course.dto.CourseExtendDto;
import com.zhihuishu.micro.course.dto.LessonDto;
import com.zhihuishu.micro.course.dto.LessonVideoDto;
import com.zhihuishu.micro.course.enums.CourseType2Enum;
import com.zhihuishu.micro.course.helper.RedisKeyHelper;
import com.zhihuishu.micro.course.helper.StringHelper;
import com.zhihuishu.micro.course.log.LoggerCollectionEnum;
import com.zhihuishu.micro.course.log.LoggerTemplateUtil;
import com.zhihuishu.micro.course.log.MDCLoggerUtil;
import com.zhihuishu.micro.course.model.MeetCourse;
import com.zhihuishu.micro.course.model.ScoreAssessRule;
import com.zhihuishu.micro.course.model.TblCourse;
import com.zhihuishu.micro.course.openapi.cc.CourseOpenService;
import com.zhihuishu.micro.course.openapi.cc.dto.ChapterWebDto;
import com.zhihuishu.micro.course.openapi.cc.dto.CourseClipsOpenDto;
import com.zhihuishu.micro.course.openapi.cc.dto.CourseExtendPropEumn;
import com.zhihuishu.micro.course.openapi.cc.dto.CourseOpenDto;
import com.zhihuishu.micro.course.openapi.cc.dto.CoursePopularizeInfoOpenDto;
import com.zhihuishu.micro.course.openapi.cc.dto.LessonVideoWebDto;
import com.zhihuishu.micro.course.openapi.cc.dto.LessonWebDto;
import com.zhihuishu.micro.course.service.AssistantsService;
import com.zhihuishu.micro.course.service.CategoryService;
import com.zhihuishu.micro.course.service.ChapterService;
import com.zhihuishu.micro.course.service.CourseClipsService;
import com.zhihuishu.micro.course.service.CourseExtendService;
import com.zhihuishu.micro.course.service.CourseService;
import com.zhihuishu.micro.course.service.CourseSpeakerService;
import com.zhihuishu.micro.course.service.LessonService;
import com.zhihuishu.micro.course.service.LessonVideoService;
import com.zhihuishu.micro.course.service.MeetCourseService;
import com.zhihuishu.micro.course.service.ScoreAssessRuleService;
import com.zhihuishu.myuni.openapi.course.ICourseRemoteService;
import com.zhihuishu.myuni.openapi.course.dto.CourseWebDto;
import com.zhihuishu.remote.ErrorCode;
import com.zhihuishu.remote.RemoteException;
import com.zhihuishu.remote.RemoteResult;
import com.zhihuishu.toolkit.helper.BeanHelper;
import com.zhihuishu.toolkit.jedis.BeanWrapper;
import com.zhihuishu.toolkit.jedis.JedisHelper;
import com.zhihuishu.toolkit.jedis.JedisHelper.Handler;
import com.zhihuishu.toolkit.jedis.JedisHelper.ReturnHandler;
import com.zhihuishu.toolkit.jedis.template.JedisExecutor;

@Service("courseOpenServiceForCC")
public class CourseOpenServiceImpl implements CourseOpenService {
    /** 日志组件 */
    private Logger logger = LoggerFactory.getLogger(this.getClass());
  

    @Resource
    private JedisExecutor jedisExecutor;

    @Resource
    private CourseService courseService;

    @Resource
    private CourseExtendService courseExtendService;

    @Resource
    private CourseClipsService courseClipsService;

    @Resource
    private ChapterService chapterService;

    @Resource
    private LessonService lessonService;

    @Resource
    private LessonVideoService lessonVideoService;

    @Resource
    private ICourseRemoteService myuniCourseRemoteService;

    @Resource
    private CategoryService categoryService;

    @Resource
    private MeetCourseService meetCourseService;

    @Resource
    private ScoreAssessRuleService scoreAssessRuleService;

    @Resource
    private IOnlineExamForCreateCourseService onlineExamForCreateCourseService;

    @Resource
    private CourseSpeakerService courseSpeakerService;

    @Resource
    private AssistantsService assistantsService;

    @Override
    public RemoteResult<CourseClipsOpenDto> queryCourseClips(long clipsId) throws RemoteException {
        RemoteResult<CourseClipsOpenDto> result = new RemoteResult<CourseClipsOpenDto>();
        try {
            CourseClipsDto clips = courseClipsService.get(clipsId);
            result.setResult(BeanHelper.transTo(clips, CourseClipsOpenDto.class));
        } catch (Exception e) {
            throw new RemoteException(e).setMessage("查询课程片花出错!");
        }

        return result;
    }

    @Override
    public RemoteResult<Void> updateCourseClips(CourseClipsOpenDto clips) throws RemoteException {
        RemoteResult<Void> result = new RemoteResult<Void>();
        // 参数检查
        if (clips == null || clips.getClipsId() == null) {
            result.setSuccess(false);
            result.setErrorCode(ErrorCode.ARGUMENTS_ILLEGALITY);
            return result;
        }
        try {
            courseClipsService.update(BeanHelper.transTo(clips, CourseClipsDto.class), -9L);
            MDCLoggerUtil.saveLogger(String.format("接口更新课程片花%s", clips), null, LoggerCollectionEnum.courseClipsCollection);
        } catch (Exception e) {
            throw new RemoteException(e).setMessage("更新课程片花执行出错!");
        }

        return result;
    }

    @Override
    public RemoteResult<Long> createCourseClips(long courseId, CourseClipsOpenDto clips)
            throws RemoteException {
        RemoteResult<Long> result = new RemoteResult<Long>();
        // 参数检查
        if (clips == null) {
            result.setSuccess(false);
            result.setErrorCode(ErrorCode.ARGUMENTS_ILLEGALITY);
            return result;
        }
        try {
            Long clipsId = courseClipsService.save(courseId, BeanHelper.transTo(clips, CourseClipsDto.class),
                    -9L);
            MDCLoggerUtil.saveLogger(String.format("接口更新课程片花%s,courseId=%d", clips,courseId), null, LoggerCollectionEnum.courseClipsCollection);
            result.setResult(clipsId);
        } catch (Exception e) {
            throw new RemoteException(e).setMessage("更新课程片花执行出错!");
        }

        return result;
    }

    @Override
    public RemoteResult<CourseOpenDto> create(String courseName, long createUser) throws RemoteException {
        RemoteResult<CourseOpenDto> result = new RemoteResult<CourseOpenDto>();
        // 参数检查
        if (courseName == null) {
            result.setSuccess(false);
            result.setErrorCode(ErrorCode.ARGUMENTS_ILLEGALITY);
            return result;
        }
        // 执行创建接口
        try {
            CourseDto course = courseService.create(courseName, createUser);
            if (course == null || course.getCourseId() == null) {
                result.setSuccess(false);
                result.setErrorCode(1);
            } else {
                CourseOpenDto cod = new CourseOpenDto();
                cod.setCourseId(course.getCourseId());
                cod.setLinkCourseId(course.getLinkCourseId());
                result.setResult(cod);
            }
            MDCLoggerUtil.saveLogger(String.format("接口创建课程,courseId=%d,courseName=%s",course.getCourseId(),courseName), createUser, LoggerCollectionEnum.courseCollection);
        } catch (Exception e) {
            throw new RemoteException(e).setMessage("创建课程执行出错!");
        }

        return result;
    }

    @Override
    public RemoteResult<String> queryCourseBackground(long courseId) throws RemoteException {
        RemoteResult<String> result = new RemoteResult<String>();
        try {
            result.setResult(courseService.getCourseBackground(courseId));
        } catch (Exception e) {
            throw new RemoteException(e).setMessage("查询课程背景出错!");
        }
        return result;
    }

    @Override
    public RemoteResult<String> queryCourseTarget(long courseId) throws RemoteException {
        RemoteResult<String> result = new RemoteResult<String>();
        try {
            result.setResult(courseService.getCourseTarget(courseId));
        } catch (Exception e) {
            throw new RemoteException(e).setMessage("查询课程目标出错!");
        }
        return result;
    }

    @Override
    public RemoteResult<String> queryCourseIntroduction(long courseId) throws RemoteException {
        RemoteResult<String> result = new RemoteResult<String>();
        try {
            result.setResult(courseService.getCourseIntroduction(courseId));
        } catch (Exception e) {
            throw new RemoteException(e).setMessage("查询课程简介出错!");
        }
        return result;
    }

    @Override
    public RemoteResult<CoursePopularizeInfoOpenDto> queryCoursePopularize(long courseId)
            throws RemoteException {
        RemoteResult<CoursePopularizeInfoOpenDto> result = new RemoteResult<CoursePopularizeInfoOpenDto>();
        try {
            CourseExtendDto ce = courseExtendService.get(courseId);
            if (ce != null) {
                CoursePopularizeInfoOpenDto cpi = new CoursePopularizeInfoOpenDto();
                cpi.setCourseId(courseId);
                cpi.setCoursePopularizeType(ce.getCoursePopularizeType());
                cpi.setCoursePopularizeContent(ce.getCoursePopularizeContent());
                result.setResult(cpi);
            }
        } catch (Exception e) {
            throw new RemoteException(e).setMessage("查询课程推广信息出错!");
        }
        return result;
    }

    @Override
    public RemoteResult<CourseOpenDto> queryCourseInfo(long courseId) throws RemoteException {
        RemoteResult<CourseOpenDto> result = new RemoteResult<CourseOpenDto>();
        try {
            CourseDto course = courseService.get(courseId);
            if (course != null) {
                CourseOpenDto basicInfo = BeanHelper.transTo(course, CourseOpenDto.class);
                result.setResult(basicInfo);
            }
        } catch (Exception e) {
            throw new RemoteException(e).setMessage("查询课程信息出错!");
        }
        return result;
    }

    @Override
    public RemoteResult<String> queryCourseImage(long courseId) throws RemoteException {
        RemoteResult<String> result = new RemoteResult<String>();
        try {
            result.setResult(courseService.getCourseImage(courseId));
        } catch (Exception e) {
            throw new RemoteException(e).setMessage("查询课程图片出错!");
        }
        return result;
    }

    @Override
    public RemoteResult<Void> update(CourseOpenDto course, long updateUser) throws RemoteException {
        RemoteResult<Void> result = new RemoteResult<Void>();
        // 参数检查
        if (course == null || course.getCourseId() == null) {
            result.setSuccess(false);
            result.setErrorCode(ErrorCode.ARGUMENTS_ILLEGALITY);
            return result;
        }
        try {
            // 执行本地更新接口
            CourseDto dto = BeanHelper.transTo(course, CourseDto.class);
            courseService.update(dto, updateUser);
            courseService.touchCourse(course.getCourseId());
            LoggerTemplateUtil.saveLogger(String.format("更新课程,courseId=%d", dto.getCourseId()), updateUser, LoggerCollectionEnum.courseCollection, dto.getCourseId());
            // 执行远程更新接口(myuni)，执行时需要判断是否存在MyuniCourseID
            Long myuniCourseId = courseService.getMyuniCourseId(course.getCourseId());
            if (myuniCourseId != null) {
                CourseWebDto cwd = new CourseWebDto();
                cwd.setOnlineCourseId(dto.getCourseId().intValue());
                cwd.setName(dto.getName());
                cwd.setCredit(dto.getCredit());
                cwd.setImg(dto.getImg());
                cwd.setIntroduction(dto.getIntroduction());
                cwd.setType(dto.getType());
                cwd.setUserId(dto.getUserId());
                cwd.setTeachTime(dto.getMeetCoursePeriod());
                cwd.setPracticeTime(dto.getOnlineCoursePeriod());
                myuniCourseRemoteService.update(cwd, updateUser);
            }
        } catch (Exception e) {
            throw new RemoteException(e).setMessage("更新课程执行出错!");
        }

        return result;
    }

    @Override
    public RemoteResult<Integer> countChapter(final long courseId) throws RemoteException {
        final RemoteResult<Integer> result = new RemoteResult<Integer>();
        jedisExecutor.execute( new Handler() {
            @Override
            public void handle(Jedis jedis) {

                Long count = jedis.scard(JedisHelper.key("cc:course", courseId, "chapters"));
                if (count.intValue() == 0) {// 查不到章测试的数量
                    // 数据库查询通过审核的章测试的数量
                    String chapterCount = jedis.hget(JedisHelper.key("cc:course", courseId),
                            "chapterTotalTotal");
                    if (chapterCount == null) {
                        chapterCount = chapterService.queryPassChapterCountByCourseId(courseId) + "";
                        jedis.hset(JedisHelper.key("cc:course", courseId), "chapterTotalTotal", chapterCount);
                    }
                    count = new Long(chapterCount);
                }
                if (count != null)
                    result.setResult(count.intValue());
            }
        });
        return result;
    }

    @Override
    public RemoteResult<Integer> countVideo(final long courseId) throws RemoteException {
        final RemoteResult<Integer> result = new RemoteResult<Integer>();
        jedisExecutor.execute( new Handler() {
            @Override
            public void handle(Jedis jedis) {
                List<String> resultList = jedis.hmget(JedisHelper.key("cc:course", courseId), "videoTotal", "type");
                String count = resultList.get(0);
                if (count == null || "0".equals(count)) {// 查不到 走数据库查询（区分微课、进阶）
                	int videoCount = 0;
                	//判断是否是微课
                	if ("2".equals(resultList.get(1))) {
                		//微课
                		videoCount = courseService.queryVideoCountForMincourse(courseId);
                	} else {
                		//进阶
                		videoCount = courseService.queryVideoCount(courseId);
                	}
                    count = String.valueOf(videoCount);
                    jedis.hset(JedisHelper.key("cc:course", courseId), "videoTotal", count);
                }
                if (count != null)
                    result.setResult(NumberUtils.toInt(count));
                else
                    result.setResult(0);
            }
        });
        return result;
    }

    @Override
    public RemoteResult<Integer> queryCourseLimitDay(long courseId) throws RemoteException {
        RemoteResult<Integer> result = new RemoteResult<Integer>();
        try {
            Map<String, String> daysMap = courseService.getStudyDays(courseId);
            if (daysMap != null) {
                result.setResult(/*Integer.valueOf(daysMap.get("reviewOrExamDays")) + */Integer.valueOf(daysMap.get("courseStudyDays")));//建课时期末考试计划天数入口关闭，不再计算期末考试计划天数
            } else {
                result.setExceptionStack(new Exception("课程为空，传入参数courseId：" + courseId));
                result.setResult(null);
                result.setSuccess(false);
            }
        } catch (Exception e) {
            throw new RemoteException(e).setMessage("根据课程ID得到课程需要的天数查询出错!传入参数courseId：" + courseId);
        }
        return result;
    }

    @Override
    public RemoteResult<Map<String, String>> queryRecruitObjAndAcademicPlan(long courseId)
            throws RemoteException {
        RemoteResult<Map<String, String>> result = new RemoteResult<Map<String, String>>();
        try {
            CourseExtendDto courseExtendDto = courseExtendService.get(courseId);
            if (courseExtendDto != null) {
                String recruitObj = courseExtendDto.getCourseRecruitObjsStr();
                String academicPlan = courseExtendDto.getCourseAcademicPrepare();
                if (StringUtils.isEmpty(recruitObj) && StringUtils.isEmpty(academicPlan)) {
                    result.setResult(null);
                } else {
                    Map<String, String> resultMap = new HashMap<String, String>();
                    resultMap.put("recruitObj", recruitObj);
                    resultMap.put("academicPlan", academicPlan);
                    result.setResult(resultMap);
                }
            } else {
                result.setResult(null);
            }
        } catch (Exception e) {
            throw new RemoteException(e).setMessage("根据课程ID，查询共享课程信息:招生对象、学术准备内容出错!传入参数courseId：" + courseId);
        }
        return result;

    }

    @Override
    public RemoteResult<Void> saveOrUpdateRecruitObjAndAcademicPlan(long courseId, String recruitObj,
            String academicPlan) throws RemoteException {
        RemoteResult<Void> result = new RemoteResult<Void>();
        try {
            CourseExtendDto courseExtendDto = new CourseExtendDto();
            courseExtendDto.setCourseRecruitObjsStr(recruitObj);
            courseExtendDto.setCourseAcademicPrepare(academicPlan);
            courseExtendDto.setCourseId(courseId);
            courseExtendService.update(courseId, courseExtendDto);
            LoggerTemplateUtil.saveLogger(String.format("保存或更新共享课程信息:招生对象、学术准备内容,courseId=%d,学术：%s，招生：%s", courseId, academicPlan, recruitObj), 
            		0L, LoggerCollectionEnum.courseCollection, courseId);
        } catch (Exception e) {
            result.setSuccess(false);
            throw new RemoteException(e).setMessage("保存或更新共享课程信息:招生对象、学术准备内容出错!传入参数courseId：" + courseId
                    + "|recruitObj:" + recruitObj + "|academicPlan:" + academicPlan);
        }
        return result;
    }

    @Override
    public RemoteResult<Void> updateCourseRedis(long courseId) throws RemoteException {
        RemoteResult<Void> r = new RemoteResult<Void>();
        try {
        	courseService.removeCourseChecheByCourseId(courseId);
            courseService.touchCourse(courseId);
        } catch (Exception e) {
            r.setExceptionStack(e);
        }
        return r;
    }

    @Override
    public RemoteResult<Void> initCourseRedis(final long courseId) throws RemoteException {
        RemoteResult<Void> remoteResult=new RemoteResult<Void>();
        queryChapterInfos(courseId);
        return remoteResult;
        /*
        RemoteResult<Void> r = new RemoteResult<Void>();
        try {
            // Touch课程缓存
            courseService.touchCourse(courseId);
            // Touch课程下章，查询章列表会初始化课程-章集合缓存、同时也会更新章Hash缓存
            List<ChapterDto> chapters = chapterService.list(courseId);
            if (CollectionUtils.isEmpty(chapters))
                return null;
            // Touch课程下节、小节
            final List<LessonDto> lessonAll = new ArrayList<LessonDto>();
            final List<LessonVideoDto> lvAll = new ArrayList<LessonVideoDto>();
            for (ChapterDto chapter : chapters) {
                if (chapter == null || chapter.getId() == null)
                    continue;
                // Touch章下节、节哈希缓存
                List<LessonDto> lessons = lessonService.list(chapter.getId());
                if (!CollectionUtils.isEmpty(lessons)) {
                    lessonAll.addAll(lessons);
                    for (LessonDto lesson : lessons) {
                        if (lesson == null || lesson.getId() == null)
                            continue;
                        // Touch节下小节、小节哈希缓存
                        List<LessonVideoDto> lvs = lessonVideoService.list(lesson.getId());
                        if (!CollectionUtils.isEmpty(lvs)) {
                            lvAll.addAll(lvs);
                        }
                    }
                }
            }
            // 课程下章节关系缓存
            if (!CollectionUtils.isEmpty(lessonAll) || !CollectionUtils.isEmpty(lvAll)) {
                jedisExecutor.execute( new Handler() {
                    @Override
                    public void handle(Jedis jedis) {
                        Pipeline pipe = jedis.pipelined();
                        // 课程下节
                        if (!CollectionUtils.isEmpty(lessonAll)) {
                            for (LessonDto lesson : lessonAll) {
                                if (lesson == null || lesson.getId() == null)
                                    continue;
                                pipe.sadd(JedisHelper.key("cc:course", courseId, "lessons"), lesson.getId()
                                        .toString());
                            }
                        }
                        // 课程下小节
                        if (!CollectionUtils.isEmpty(lvAll)) {
                            for (LessonVideoDto lv : lvAll) {
                                if (lv == null || lv.getId() == null)
                                    continue;
                                pipe.sadd(JedisHelper.key("cc:course", courseId, "lvs"), lv.getId()
                                        .toString());
                            }
                        }
                    }
                });

            }
        } catch (Exception e) {
            r.setExceptionStack(e);
        }
        return r;
    */}

    @Override
    public RemoteResult<Map<Long, Map<String, Integer>>> findProgressByCourseIds(final List<Long> courseIds)
            throws RemoteException {
        RemoteResult<Map<Long, Map<String, Integer>>> result = new RemoteResult<Map<Long, Map<String, Integer>>>();
        if (CollectionUtils.isEmpty(courseIds)) {
            result.setSuccess(false);
            result.setExceptionStack(new Exception("参数不合法:课程id为空！"));
            result.setErrorCode(ErrorCode.ARGUMENTS_ILLEGALITY);
            return result;
        }

        Map<Long, Map<String, Integer>> transMap = new HashMap<Long, Map<String, Integer>>();

        final Map<Long, Map<String, String>> map = new HashMap<Long, Map<String, String>>();

        final List<Long> noRedisCourseIds = new ArrayList<Long>();
//        Jedis jedis = null;
        try {
//            jedis = jedisPool.getResource();
            jedisExecutor.execute(new Handler() {
            	@Override
            	public void handle(Jedis jedis) {
		            String progressInfoKey = "";
		            for (Long courseId : courseIds) {
		                progressInfoKey = RedisKeyHelper.getProgressInfoKey(courseId);
		                // 如果redis中存在，就在redis中取，如果不存在，走库，并且保存到redis
		                if (jedis.exists(progressInfoKey)) {
		                    map.put(courseId, jedis.hgetAll(RedisKeyHelper.getProgressInfoKey(courseId)));
		                } else {
		                    noRedisCourseIds.add(courseId);
		                }
		            }
             	}
            });
            if (noRedisCourseIds.size() > 0) {
                Map<Long, Map<String, String>> sqlMap = getProgressInfo(noRedisCourseIds);
                if (sqlMap != null && sqlMap.size() > 0) {
                    map.putAll(sqlMap);
                }

            }
            // 类型转换
            transMap = transMap(map);
            result.setResult(transMap);
        } catch (Exception e) {
            e.printStackTrace();
            result.setSuccess(false);
            throw new RemoteException(e).setMessage("查询课程进度信息出错!");

        }
        return result;
    }
  
    public Map<Long, Map<String, String>> getProgressInfo(List<Long> courseIds) {

        List<TblCourse> list = courseService.findCourseByCourseIds(courseIds);
        Map<Long, Map<String, String>> map = null;
        if (!CollectionUtils.isEmpty(list)) {
            map = new HashMap<Long, Map<String, String>>();
            Map<String, String> infoMap = null;
            Map<String, Integer> fillCountMap = null;
            for (TblCourse course : list) {
                if (course != null) {
                    infoMap = new HashMap<String, String>();
                    fillCountMap = new HashMap<String, Integer>();
                    int mold = 0; // mold（课程模式）:1老版建课、2新版本建课、3私有云建课、4海外建课、10微课程
                    fillCountMap.put("filledCount", 0);   // 已填数初始化为0
                    fillCountMap.put("unFilledCount", 0); // 未填数初始化为0
                    
                    mold = initializeCourseType(course,mold); //初始化区分当前课程类型
                   
                    if (mold == CourseType2Enum.V1TYPE.getType() || 
                    		mold == CourseType2Enum.PRIVATECLOUDTYPE.getType() || 
                    		mold == CourseType2Enum.MINTYPE.getType()) { 
                    	//公共部分基础信息完整度必填项和非必填项统计
                    	publicBasicInfoProgressCount(course,mold,fillCountMap);                       
                    }

                    if (mold == CourseType2Enum.V1TYPE.getType()) {
                    	//纯老版课程完整度必填项和非必填项统计
                    	v1CourseProgressCount(course,mold,fillCountMap);
                    }

                    if (mold == CourseType2Enum.V2TYPE.getType()) {
                    	//纯新版建课完整度必填项和非必填项统计
                    	v2CourseProgressCount(course,mold,fillCountMap);
                    }
                    
                    if(mold == CourseType2Enum.FOREIGNTYPE.getType()){
                    	//海外建课完整度必填项和非必填项统计
                    	foreignProgressCount(course,mold,fillCountMap);
                    }

                    if (mold == CourseType2Enum.V1TYPE.getType() || mold == CourseType2Enum.V2TYPE.getType() || 
                    		mold == CourseType2Enum.FOREIGNTYPE.getType()||mold == CourseType2Enum.MINTYPE.getType()) {
                    	//期末考试完整度必填项和非必填项统计
                    	examProgressCount(course,mold,fillCountMap); 
                    }
                    
                    //章节完整度必填项和非必填统计
                    chapterProgressCount(course,mold,fillCountMap); 
                   
                    // 微课程没有考核标准
                    if (mold == CourseType2Enum.V1TYPE.getType() || mold == CourseType2Enum.V2TYPE.getType() ||
                    		mold == CourseType2Enum.PRIVATECLOUDTYPE.getType() || mold == CourseType2Enum.FOREIGNTYPE.getType()) {
                    	scoreAssessRuleProgressCount(course,mold,fillCountMap);
                    }
                    
                    int filledCount = fillCountMap.get("filledCount");
                    int unFilledCount = fillCountMap.get("unFilledCount");
                    int progress = (int) Math.rint(filledCount * 100.0 / (filledCount + unFilledCount));
                    if (progress == 0) {
                        progress = 2; // 如果没填数据，进度默认为2%
                    }
                    infoMap.put("progress", progress + ""); // 完整度百分比
                    infoMap.put("mold", mold + ""); // （课程模式）:1老版建课、2新版本建课、3私有云建课、4海外建课、10微课程
                    infoMap.put("filledTotalCount", filledCount + unFilledCount + ""); // 必填项总数
                    infoMap.put("unFilledCount", unFilledCount + ""); // 未填数
                    map.put(course.getCourseId(), infoMap);

                }
            }
            //添加到redis
            putProgressInfoToRedis(map);
           
        }

        return map;

    }

    /**
     * 初始化区分当前课程类型
     * @author yulijin
     * @date 2016年10月20日 下午3:13:10 
     * @param course
     * @param mold
     */
    private int initializeCourseType (TblCourse course,int mold){
    	 if (course.getType() != null && course.getType().equals(1)
                 && course.getTurnType() != null && course.getTurnType().equals(0)
                 && course.getFirstStepStat() == null) {
    		 
             mold = CourseType2Enum.V1TYPE.getType(); // 老版建课
         }

         if (course.getFirstStepStat() != null) {
             mold = CourseType2Enum.V2TYPE.getType(); // 新版建课
         }

         if (course.getTurnType() != null && course.getTurnType().equals(1) && (!"4".equals(course.getType()+""))) {
             mold =  CourseType2Enum.PRIVATECLOUDTYPE.getType(); // 私有云建课
         }

         if (course.getType() != null && course.getType().equals(4)) {
             mold = CourseType2Enum.FOREIGNTYPE.getType(); // 海外建课
         }

         if (course.getType() != null && course.getType().equals(2)) {
             mold = CourseType2Enum.MINTYPE.getType(); // 微课程
         }
         return mold;
    }
    /**
     * 公共部分基础信息完整度必填项和非必填项统计
     * @author yulijin
     * @date 2016年10月21日 下午4:42:51 
     * @param course
     * @param mold
     * @param filledCount
     * @param unFilledCount
     */
    private void publicBasicInfoProgressCount(TblCourse course,int mold,Map<String, Integer> fillCountMap){
    	int filledCount = fillCountMap.get("filledCount");
    	int unFilledCount = fillCountMap.get("unFilledCount");
    	if (StringUtils.isEmpty(course.getName())) {
            unFilledCount++;
            logger.debug("===>课程名称为空");
            unFillProgressLogger("课程名称为空，课程类型："+mold,course.getCourseId());
        } else {
            filledCount++;
        }

        if (StringUtils.isEmpty(course.getImg())) {
            unFilledCount++;
            logger.debug("===>课程图片为空");
            unFillProgressLogger("课程图片为空，课程类型："+mold,course.getCourseId());
        } else {
            filledCount++;
        }

        List<CourseCategoryDto> courseLabels = categoryService.listByCourse(course
                .getCourseId());
        if (CollectionUtils.isEmpty(courseLabels)) {
            unFilledCount++;
            logger.debug("===>课程分类为空");
            unFillProgressLogger("课程分类为空，课程类型："+mold,course.getCourseId());
        } else {
            filledCount++;
        }

        if (mold != 10) {
            if (StringUtils.isEmpty(course.getCcCourse().getTeamData())) {
                unFilledCount++;
                logger.debug("===>课程团队为空");
                unFillProgressLogger("课程团队为空，课程类型："+mold,course.getCourseId());
            } else {
                filledCount++;
            }
        } else {
            int count = assistantsService.findAssistantsCount(course.getCourseId());
            if (count == 0) {
                unFilledCount++;
                logger.debug("===>微课程团队为空");
                unFillProgressLogger("微课程团队为空，课程类型："+mold,course.getCourseId());
            } else {
                filledCount++;
            }
            if (course.getCcCourse().getVideoId() == null) {
                unFilledCount++;
                logger.debug("===>微课程片花为空");
                unFillProgressLogger("微课程片花为空，课程类型："+mold,course.getCourseId());
            } else {
                filledCount++;
            }
        }

        if (StringUtils.isEmpty(course.getIntroduction())) {
            unFilledCount++;
            logger.debug("===>课程简介为空");
            unFillProgressLogger("课程简介为空，课程类型："+mold,course.getCourseId());
        } else {
            filledCount++;
        }
    	fillCountMap.put("filledCount", filledCount);
    	fillCountMap.put("unFilledCount", unFilledCount);
    }
    /**
     * 纯老版课程完整度必填项和非必填项统计
     * @author yulijin
     * @date 2016年10月20日 下午3:55:04
     */
    private void v1CourseProgressCount(TblCourse course,int mold,Map<String,Integer> fillCountMap){
    	 int filledCount = fillCountMap.get("filledCount");
    	 int unFilledCount = fillCountMap.get("unFilledCount");
    	 if (course.getCcCourse().getVideoId() == null) {
             unFilledCount++;
             logger.debug("===>课程片花为空");
             unFillProgressLogger("课程片花为空，课程类型："+mold,course.getCourseId());
         } else {
             filledCount++;
         }

         if (StringUtils.isEmpty(course.getCcCourse().getMoiveDesc())) {
             unFilledCount++;
             logger.debug("===>课程片花描述为空");
             unFillProgressLogger("课程片花描述为空，课程类型："+mold,course.getCourseId());
         } else {
             filledCount++;
         }

//         if (course.getCcCourse().getLimitDay() == null) {
//             unFilledCount++;
//             log.debug("===>教学计划为空");
//             unFillProgressLogger("教学计划为空，课程类型："+mold,course.getCourseId());
//         } else {
//             filledCount++;
//         }
//
//         if (course.getCcCourse().getStudyHour() == null) {
//             unFilledCount++;
//             log.debug("===>最低学时为空");
//             unFillProgressLogger("最低学时为空，课程类型："+mold,course.getCourseId());
//         } else {
//             filledCount++;
//         }
    	 fillCountMap.put("filledCount",filledCount);
    	 fillCountMap.put("unFilledCount",unFilledCount);
    }
    /**
     * 纯新版建课完整度必填项和非必填项统计
     * @author yulijin
     * @date 2016年10月20日 下午4:12:26 
     * @param course
     * @param mold
     * @param filledCount
     * @param unFilledCount
     */
    private void v2CourseProgressCount(TblCourse course,int mold,Map<String,Integer> fillCountMap){
	   	int filledCount = fillCountMap.get("filledCount");
	   	int unFilledCount = fillCountMap.get("unFilledCount");
        if (course.getFirstStepStat() != null) {
            if (course.getFirstStepStat().getBackgroundStat().equals(0)) {
                unFilledCount++;
                logger.debug("===>课程背景为空");
                unFillProgressLogger("课程背景为空，课程类型："+mold,course.getCourseId());
            } else {
                filledCount++;
            }
            if (course.getFirstStepStat().getTagetStat().equals(0)) {
                unFilledCount++;
                logger.debug("===>课程目标为空");
                unFillProgressLogger("课程目标为空，课程类型："+mold,course.getCourseId());
            } else {
                filledCount++;
            }

            if (course.getFirstStepStat().getIntroduceStat().equals(0)) {
                unFilledCount++;
                logger.debug("===>课程简介为空");
                unFillProgressLogger("课程简介为空，课程类型："+mold,course.getCourseId());
            } else {
                filledCount++;
            }

            if (course.getFirstStepStat().getBaseInfoStat().equals(0)) {
                unFilledCount++;
                logger.debug("===>课程基本信息为空");
                unFillProgressLogger("课程基本信息为空，课程类型："+mold,course.getCourseId());
            } else {
                filledCount++;
            }

            if (course.getCcCourse().getVideoId() == null
                    || StringUtils.isEmpty(course.getCcCourse().getMoiveDesc())) {
                unFilledCount++;
                logger.debug("===>新版课程片花或者片花描述为空");
                unFillProgressLogger("新版课程片花或者片花描述为空，课程类型："+mold,course.getCourseId());
            } else {
                filledCount++;
            }

            if (StringUtils.isEmpty(course.getImg())) {
                unFilledCount++;
                logger.debug("===>课程图片为空");
                unFillProgressLogger("课程图片为空，课程类型："+mold,course.getCourseId());
            } else {
                filledCount++;
            }
        }
        Map<String,Boolean> userTypeMap = courseSpeakerService.findCourseSpeakerIsComplete(course.getCourseId(),2);

        if (userTypeMap.get("plan") == false) {
            unFilledCount++;
            logger.debug("===>新版建课课程负责人为空（学术总策划）");
            unFillProgressLogger("新版建课课程负责人为空（学术总策划），课程类型："+mold,course.getCourseId());
        } else {
            filledCount++;
        }

//        if (userTypeMap.get("team") == false) {
//            unFilledCount++;
//            logger.debug("===>新版建课课程教学团队为空");
//            unFillProgressLogger("新版建课课程教学团队为空，课程类型："+mold,course.getCourseId());
//        } else {
//            filledCount++;
//        }
        if (course.getCourseMode() != null && !course.getCourseMode().equals(2)) {
            List<MeetCourse> meetCourses = meetCourseService.getMeetCourseList(course.getCourseId());
	       	if(!CollectionUtils.isEmpty(meetCourses)){
	       		 boolean flag = true; 
	       		 for(MeetCourse meetCourse:meetCourses){
	       			 if(meetCourse.getComplete()==false){
	       				flag = false;
	       				break;
	       			 }
	       		 }
	       		 if(flag == false){
	       			unFilledCount++;
	                logger.debug("===>见面课数据不完整");
	                unFillProgressLogger("见面课数据不完整（检查app建课见面课教学要求字段），课程类型："+mold,course.getCourseId());
	       		 }else{
	       			filledCount++;
	       		 }
	       	}else{
	       		unFilledCount++;
                logger.debug("===>见面课无数据");
                unFillProgressLogger("见面课无数据，课程类型："+mold,course.getCourseId());
	       	}
        }
		fillCountMap.put("filledCount",filledCount);
		fillCountMap.put("unFilledCount",unFilledCount);
    }
    /**
     * 海外建课完整度必填项和非必填项统计
     * @author yulijin
     * @date 2016年10月20日 下午4:43:51 
     * @param course
     * @param mold
     * @param filledCount
     * @param unFilledCount
     */
    private void foreignProgressCount(TblCourse course,int mold,Map<String,Integer> fillCountMap){
	   	 int filledCount = fillCountMap.get("filledCount");
	   	 int unFilledCount = fillCountMap.get("unFilledCount");
    	 if (StringUtils.isEmpty(course.getName())) {
             unFilledCount++;
             logger.debug("===>课程名称为空");
             unFillProgressLogger("课程名称为空，课程类型："+mold,course.getCourseId());
         } else {
             filledCount++;
         }
    	 if (StringUtils.isEmpty(course.getImg())) {
             unFilledCount++;
             logger.debug("===>课程图片为空");
             unFillProgressLogger("课程图片为空，课程类型："+mold,course.getCourseId());
         } else {
             filledCount++;
         }
    	 
    	 if (course.getCredit()==null||course.getCredit()==0) {
             unFilledCount++;
             logger.debug("===>学分为空");
             unFillProgressLogger("学分为空，课程类型："+mold,course.getCourseId());
         } else {
             filledCount++;
         }
    	 
    	 if (course.getCourseCategory()==null) {
             unFilledCount++;
             logger.debug("===>课程类别为空");
             unFillProgressLogger("课程类别为空，课程类型："+mold,course.getCourseId());
         } else {
             filledCount++;
         }
    	 Map<String,Boolean> userTypeMap = courseSpeakerService.findCourseSpeakerIsComplete(course.getCourseId(),4);
    	 if(userTypeMap.get("all")==false){
    		 unFilledCount++;
             logger.debug("===>教学团队为空");
             unFillProgressLogger("教学团队为空，课程类型："+mold,course.getCourseId());
    	 }else{
    		 filledCount++; 
    	 }
    	 
         if (course.getCcCourse().getVideoId() == null) {
             unFilledCount++;
             logger.debug("===>课程片花为空");
             unFillProgressLogger("课程片花为空，课程类型："+mold,course.getCourseId());
         } else {
             filledCount++;
         }
         
         CourseExtendDto extendDto = courseExtendService.get(course.getCourseId());
         if(course==null||StringUtils.isEmpty(course.getSchoolName())) {
             unFilledCount++;
             logger.debug("===>学校机构为空");
             unFillProgressLogger("学校机构为空，课程类型："+mold,course.getCourseId());
         } else {
             filledCount++;
         }
    	 if (extendDto==null || extendDto.getOnlineCoursePeriod()==null||extendDto.getOnlineCoursePeriod()==0
    			 ||extendDto.getMeetCoursePeriod()==null||extendDto.getMeetCoursePeriod()==0) {
             unFilledCount++;
             logger.debug("===>学时为空");
             unFillProgressLogger("学时为空，课程类型："+mold,course.getCourseId());
         } else {
             filledCount++;
         }
         if(extendDto==null||StringUtils.isEmpty(extendDto.getCourseAcademicPrepare())){
        	 unFilledCount++;
             logger.debug("===>学术准备内容为空");
             unFillProgressLogger("学术准备内容为空，课程类型："+mold,course.getCourseId());
         }else{
        	 filledCount++;
         }
         if(extendDto==null||StringUtils.isEmpty(extendDto.getCourseBackground())){
        	 unFilledCount++;
             logger.debug("===>课程背景为空");
             unFillProgressLogger("课程背景为空，课程类型："+mold,course.getCourseId());
         }else{
        	 filledCount++;
         }
         if(extendDto==null||StringUtils.isEmpty(extendDto.getCourseTarget())){
        	 unFilledCount++;
             logger.debug("===>课程目标为空");
             unFillProgressLogger("课程目标为空，课程类型："+mold,course.getCourseId());
         }else{
        	 filledCount++;
         }
    	 if (StringUtils.isEmpty(course.getIntroduction())) {
             unFilledCount++;
             logger.debug("===>课程简介（设计原则）为空");
             unFillProgressLogger("课程简介（设计原则）为空，课程类型："+mold,course.getCourseId());
         } else {
             filledCount++;
         }
    	 if (extendDto==null||StringUtils.isEmpty(extendDto.getLearningOutcomes())) {
             unFilledCount++;
             logger.debug("===>学习成果为空");
             unFillProgressLogger("学习成果为空，课程类型："+mold,course.getCourseId());
         } else {
             filledCount++;
         }
    	 if (extendDto==null||StringUtils.isEmpty(extendDto.getLearningMethods())) {
             unFilledCount++;
             logger.debug("===>学习方法为空");
             unFillProgressLogger("学习方法为空，课程类型："+mold,course.getCourseId());
         } else {
             filledCount++;
         }
    	 
    	 List<MeetCourse> meetCourses = meetCourseService.getMeetCourseList(course.getCourseId());
    	 if(!CollectionUtils.isEmpty(meetCourses)){
    		 for(MeetCourse meetCourse:meetCourses){
    			 if(meetCourse.getComplete()==false){
    				 unFilledCount++;
    	             logger.debug("===>名称为"+meetCourse.getCourseTopic()+"的见面课不完整");
    	             unFillProgressLogger("名称为"+meetCourse.getCourseTopic()+"的见面课不完整，课程类型："+mold,course.getCourseId());
    			 }else{
    				 filledCount++;
    			 }
    		 }
    		 
    	 }else{
    		 unFilledCount++;
             logger.debug("===>见面课无数据");
             unFillProgressLogger("见面课无数据，课程类型："+mold,course.getCourseId());
    	 }
    	fillCountMap.put("filledCount",filledCount);
 		fillCountMap.put("unFilledCount",unFilledCount);
    }
    /**
     * 期末考试完整度必填项和非必填项统计
     * @author yulijin
     * @date 2016年10月24日 上午8:28:18 
     * @param course
     * @param mold
     * @param filledCount
     * @param unFilledCount
     */
    private void examProgressCount(TblCourse course,int mold,Map<String,Integer> fillCountMap){
	   	int filledCount = fillCountMap.get("filledCount");
	   	int unFilledCount = fillCountMap.get("unFilledCount");
    	List<ExamCourseDto> examCourseDtos = onlineExamForCreateCourseService
                .listExamCourseForCreateCourse(Integer.valueOf(course.getCourseId()
                        .toString()));
        boolean usePaperFlag = false;
        if (examCourseDtos != null && examCourseDtos.size() > 0) {
            for (ExamCourseDto examCourseDto : examCourseDtos) {
                if (examCourseDto.getType() != null && examCourseDto.getType().equals(1)) {
                    usePaperFlag = true;
                    // 微课程
                    if (mold == CourseType2Enum.MINTYPE.getType()
                            && (examCourseDto.getQuestionNumber() == null || Integer
                                    .valueOf(examCourseDto.getQuestionNumber()) <= 0 || 
                                    examCourseDto.getLimitTime()==null || examCourseDto.getLimitTime()==0)) {
                        usePaperFlag = false;
                    }
                    if(mold == CourseType2Enum.FOREIGNTYPE.getType()
                    		&& (StringUtils.isEmpty(examCourseDto.getExamName()) 
                    				|| examCourseDto.getQuestionNumber() == null
                    				|| examCourseDto.getQuestionNumber() == 0 
                    				|| examCourseDto.getLimitTime()==null 
                    				|| examCourseDto.getLimitTime()==0)){
                    	usePaperFlag = false;
                    	
                    }
                }
            }
        }
        if (usePaperFlag == false) {
            unFilledCount++;
            logger.debug("===>期末考试为空");
            unFillProgressLogger("期末考试为空，课程类型："+mold,course.getCourseId());
        } else {
            filledCount++;
        }
    	fillCountMap.put("filledCount",filledCount);
 		fillCountMap.put("unFilledCount",unFilledCount);
    }
    /**
     * 章节完整度必填项和非必填项统计
     * @author yulijin
     * @date 2016年10月24日 上午8:37:51 
     * @param course
     * @param mold
     * @param filledCount
     * @param unFilledCount
     */
    private void chapterProgressCount(TblCourse course,int mold,Map<String,Integer> fillCountMap){
	   	 int filledCount = fillCountMap.get("filledCount");
	   	 int unFilledCount = fillCountMap.get("unFilledCount");
    	 List<ChapterDto> chapterDtos = chapterService.findChaptersByCourseId(course.getCcCourse()
                 .getId());
         if (!CollectionUtils.isEmpty(chapterDtos)) {
             for (ChapterDto chapterDto : chapterDtos) {
                 if (chapterDto.getIsPass() == null || chapterDto.getIsPass().equals(0)) {
                     unFilledCount++;
                     logger.debug("===>第" + chapterDto.getRank() + "章有资料不全");
                     unFillProgressLogger("第" + chapterDto.getRank() + "章资料不全，课程类型："+mold,course.getCourseId());
                 } else {
                     filledCount++;
                 }
             }
         }
         if(mold == CourseType2Enum.FOREIGNTYPE.getType()){
        	 if(CollectionUtils.isEmpty(chapterDtos)){
        		 unFilledCount++;
        		 logger.debug("===>章无数据");
        		 unFillProgressLogger("章无数据，课程类型："+mold,course.getCourseId());
        	 }
         }
     	fillCountMap.put("filledCount",filledCount);
  		fillCountMap.put("unFilledCount",unFilledCount);
    }
	 /**
	 * 考核标准完整度必填项和非必填项统计
	 * @author yulijin
	 * @date 2016年10月24日 上午8:48:11 
	 * @param course
	 * @param mold
	 * @param filledCount
	 * @param unFilledCount
	 */
    private void scoreAssessRuleProgressCount(TblCourse course,int mold,Map<String,Integer> fillCountMap){
	   	int filledCount = fillCountMap.get("filledCount");
	   	int unFilledCount = fillCountMap.get("unFilledCount");
	   	ScoreAssessRule scoreAssessRule = scoreAssessRuleService.findByCourseId(course.getCourseId());
   		if(scoreAssessRule != null){
	       	List<MeetCourse> meetCourses = meetCourseService.getMeetCourseList(course.getCourseId());
   			Double onlineScoreShare = scoreAssessRule.getOnlineScoreShare();                //线上成绩占比
   			Double chapterTestScoresShare = scoreAssessRule.getChapterTestScoresShare();    //章测试分数占比
   			Double learningProcessScoresShare = scoreAssessRule.getLearningProcessScoresShare();  //学习进度成绩分数占比
   			Double meetCourseScoreShare = scoreAssessRule.getMeetCourseScoreShare();	//见面课成绩占比
   			Double finalExamScoreShare = scoreAssessRule.getFinalExamScoreShare();		//期末考试成绩占比
   			Double bbsScore = scoreAssessRule.getBbsScore();                            //论坛得分
   			if(mold == CourseType2Enum.FOREIGNTYPE.getType()){
		       	boolean meetFlag = false ; //见面课现场得分和考勤分是否完整
		    	if(!CollectionUtils.isEmpty(meetCourses)){
		    		for(MeetCourse meetCourse:meetCourses){
		    			if(meetCourse.getCheckScore() == null || meetCourse.getSiteScore() == null){
		    				meetFlag = true ;
		    				break;
		    			}
		    		}
		    	}
	   			if(meetFlag || chapterTestScoresShare == null || learningProcessScoresShare == null 
	   					|| meetCourseScoreShare == null || finalExamScoreShare ==null 
	   					|| bbsScore == null || add(chapterTestScoresShare,learningProcessScoresShare
	   							,meetCourseScoreShare,finalExamScoreShare,bbsScore) != 100){
				    unFilledCount++;
				    logger.debug("===>考核标准为空");
				    unFillProgressLogger("考核标准为空，课程类型："+mold,course.getCourseId());
	   			}else{
	   				filledCount++;
	   			}
   			}else{
   				onlineScoreShare = onlineScoreShare == null ? 0 : onlineScoreShare ;            //线上成绩占比
   	   			meetCourseScoreShare = meetCourseScoreShare == null ? 0 : meetCourseScoreShare;	//见面课成绩占比
   	   			finalExamScoreShare = finalExamScoreShare == null ? 0 : finalExamScoreShare;	//期末考试成绩占比
   	   			bbsScore = bbsScore == null ? 0 : bbsScore;                                     //论坛得分
   				if(CourseModeConstant.COURSE_MODE_2.equals(course.getCourseMode()+"")){
   					//如果是纯在线课程，则没有见面课
   					meetCourseScoreShare = 0.0;
   				}
   	   			boolean flag = false ;
   	   			//论坛作为附加分
   	   			if(scoreAssessRule.getIsAddScore() != null 
   	   					&& scoreAssessRule.getIsAddScore().equals(1)){
   	   				if(add(onlineScoreShare,meetCourseScoreShare,finalExamScoreShare,0,0) != 100){
   	   					flag = true;
   	   				}
   	   			}else{
   	   				//论坛不作为附加分，即100分内
   	   				if(add(onlineScoreShare,meetCourseScoreShare,finalExamScoreShare,bbsScore,0) != 100){
   	   					flag = true;
   	   				}
   	   			}
	   			//判断见面课各项分相加是否等于见面课设置分、考勤分和现场得分是否为空
	   			if(!CourseModeConstant.COURSE_MODE_2.equals(course.getCourseMode()+"")){
	   				Double checkAddSiteScore = 0.0;
	   				if(!CollectionUtils.isEmpty(meetCourses)){
		   				for(MeetCourse meetCourse:meetCourses){
		   					final Long meetCourseId = meetCourse.getMeetCourseId();
		   					BeanWrapper<MeetCourse> bw = jedisExecutor.executeAndReturn(new ReturnHandler<MeetCourse>() {
		   						String cleanedMeetCourseKey = RedisKeyHelper.getCleanedMeetCourseKey(meetCourseId);
		   						@Override
		   						public MeetCourse handle(Jedis jedis) {
		   							MeetCourse mc = null;
		   			                if (!jedis.exists(cleanedMeetCourseKey)) {
		   			                	meetCourseService.removeCache(meetCourseId);
		   			                	mc = meetCourseService.getMeetCourse(meetCourseId);
		   			                	jedis.set(cleanedMeetCourseKey, meetCourseId+"");
		   			                }
		   							return mc;
		   						}
		   					});
		   					if(bw.getValue() != null){
			   					meetCourse = bw.getValue();
		   					}
		   					
		   					if(meetCourse.getIsAddScore() == null || meetCourse.getIsAddScore().equals(0)){
		   						continue;
		   					}
			    			if(meetCourse.getCheckScore() == null || meetCourse.getSiteScore() == null){
			    				flag = true;
			    				break;
			    			}
			    			checkAddSiteScore += add(meetCourse.getCheckScore(),meetCourse.getSiteScore());
			    		}
	   				}
	   				if(!checkAddSiteScore.equals(meetCourseScoreShare)){
	   					flag = true;
	   				}
	   			}
   				if (flag) {
   				    unFilledCount++;
   				    logger.debug("===>考核标准为空");
   				    unFillProgressLogger("考核标准为空，课程类型："+mold,course.getCourseId());
   				} else {
   				    filledCount++;
   				}
   			}
   		}else{
		    unFilledCount++;
		    logger.debug("===>考核标准为空");
		    unFillProgressLogger("考核标准为空，课程类型："+mold,course.getCourseId());
   		}

     	fillCountMap.put("filledCount",filledCount);
  		fillCountMap.put("unFilledCount",unFilledCount);
    }

    /**
     * 将课程完整度信息添加至redis
     * @author yulijin
     * @date 2016年10月21日 上午8:38:50 
     * @param map
     */
    private void putProgressInfoToRedis(final Map<Long, Map<String, String>> map){
		/*Jedis jedis = null;
		try {
		    jedis = jedisPool.getResource();
		    Pipeline pip = jedis.pipelined();
		    String progressInfoKey = "";
		    for (Long courseId : map.keySet()) {
		        progressInfoKey = RedisKeyHelper.getProgressInfoKey(courseId);
		        if (map.get(courseId) != null) {
		            pip.hmset(progressInfoKey, map.get(courseId));
		        }
		
		    }
		} finally {
		    JedisHelper.closeQuietly(jedis);
		}*/
        jedisExecutor.execute(new Handler() {
            
            @Override
            public void handle(Jedis jedis) {
                Pipeline pip = jedis.pipelined();
                String progressInfoKey = "";
                for (Long courseId : map.keySet()) {
                    progressInfoKey = RedisKeyHelper.getProgressInfoKey(courseId);
                    if (map.get(courseId) != null) {
                        pip.hmset(progressInfoKey, map.get(courseId));
                    }
            
                }
                
            }
        });
    }
    //添加日志
    private void unFillProgressLogger(String message,Long courseId) {
        MDCLoggerUtil.saveLogger(message, null, LoggerCollectionEnum.courseProgressCollection,courseId);
    }
    private double add(double num1,double num2,double num3,double num4,double num5){
        BigDecimal   bd1   =   new   BigDecimal(Double.toString(num1));  
        BigDecimal   bd2   =   new   BigDecimal(Double.toString(num2)); 
        BigDecimal   bd3   =   new   BigDecimal(Double.toString(num3));  
        BigDecimal   bd4   =   new   BigDecimal(Double.toString(num4)); 
        BigDecimal   bd5   =   new   BigDecimal(Double.toString(num5));
        return bd1.add(bd2).add(bd3).add(bd4).add(bd5).doubleValue();
    }
    private double add(double num1,double num2){
        BigDecimal   bd1   =   new   BigDecimal(Double.toString(num1));  
        BigDecimal   bd2   =   new   BigDecimal(Double.toString(num2)); 
        return bd1.add(bd2).doubleValue();
    }
    @Override
    public RemoteResult<Void> delProgressByCourseIds(final List<Long> courseIds) throws RemoteException {
        RemoteResult<Void> r = new RemoteResult<Void>();
        if (!CollectionUtils.isEmpty(courseIds)) {
            /*Jedis jedis = null;
            try {
                jedis = jedisPool.getResource();
                Pipeline pip = jedis.pipelined();
                String progressInfoKey = "";
                for (Long courseId : courseIds) {
                    progressInfoKey = RedisKeyHelper.getProgressInfoKey(courseId);
                    pip.del(progressInfoKey);
                }
            } finally {
                JedisHelper.closeQuietly(jedis);
            }*/
            jedisExecutor.execute(new Handler() {
                
                @Override
                public void handle(Jedis jedis) {
                    Pipeline pip = jedis.pipelined();
                    String progressInfoKey = "";
                    for (Long courseId : courseIds) {
                        progressInfoKey = RedisKeyHelper.getProgressInfoKey(courseId);
                        pip.del(progressInfoKey);
                    }
                    
                }
            });
        }
        return r;
    }

    private Map<Long, Map<String, Integer>> transMap(Map<Long, Map<String, String>> map) {
        Map<Long, Map<String, Integer>> transMap = null;
        if (!CollectionUtils.isEmpty(map)) {
            transMap = new HashMap<Long, Map<String, Integer>>();
            Map<String, Integer> infoMap = null;
            for (Long courseId : map.keySet()) {
                infoMap = new HashMap<String, Integer>();
                if (!CollectionUtils.isEmpty(map.get(courseId))) {
                    for (String key : map.get(courseId).keySet()) {
                        infoMap.put(
                                key,
                                StringUtils.isEmpty(map.get(courseId).get(key)) ? null : Integer.parseInt(map
                                        .get(courseId).get(key)));
                    }
                }
                transMap.put(courseId, infoMap);
            }
        }
        return transMap;
    }

    @Override
    public RemoteResult<Map<Long, List<Long>>> findCourseIdFamilysByCourseIds(List<Long> courseIds)
            throws RemoteException {
        RemoteResult<Map<Long, List<Long>>> result = new RemoteResult<Map<Long, List<Long>>>();
        if (CollectionUtils.isEmpty(courseIds)) {
            result.setSuccess(false);
            result.setExceptionStack(new Exception("参数不合法:课程id为空！"));
            result.setErrorCode(ErrorCode.ARGUMENTS_ILLEGALITY);
            return result;
        }
        try {
            Map<Long, List<Long>> map = new HashMap<Long, List<Long>>();
            List<Long> ids = null;
            Long rootCourseId = null;
            for (Long courseId : courseIds) {
                rootCourseId = courseService.findRootCourseIdByCourseId(courseId);
                if (rootCourseId != null) {
                    ids = courseService.findCourseIdFamilysByCourseId(rootCourseId);
                    if (ids != null && ids.size() > 0) {
                        ids.add(rootCourseId);
                        map.put(courseId, ids);
                    }
                } else {
                    ids = courseService.findCourseIdFamilysByCourseId(courseId);
                    if (ids != null && ids.size() > 0) {
                        ids.add(courseId);
                        map.put(courseId, ids);
                    } else {
                        ids = new ArrayList<Long>();
                        ids.add(courseId);
                        map.put(courseId, ids);
                    }
                }

            }
            result.setResult(map);
        } catch (Exception e) {
            e.printStackTrace();
            result.setSuccess(false);
            throw new RemoteException(e).setMessage("查询复制家族课程ids出错!");
        }
        return result;
    }

    @Override
    public RemoteResult<List<ChapterWebDto>> queryChapterInfos(final long courseId) throws RemoteException {

        RemoteResult<List<ChapterWebDto>> result = new RemoteResult<List<ChapterWebDto>>();

        // 参考com.zhihuishu.micro.course.openapi.cc.impl.ChapterLessonOpenServiceImpl#queryChapterBasicInfos逻辑
        final List<ChapterWebDto> chapters = new ArrayList<ChapterWebDto>();
        jedisExecutor.execute( new Handler() {
            @Override
            public void handle(Jedis jedis) {
                // 根据课程ID，获取章列表
                Set<String> chapterIds = jedis.smembers(JedisHelper.key("cc:course", courseId, "chapters"));
                if (CollectionUtils.isEmpty(chapterIds)) {
                    chapterIds=chapterService.queryPassChapterIdsByCourseIdAndAddToCache(courseId);
                }
                // 根据课程ID，获取节列表
                Set<String> lessonIds = jedis.smembers(JedisHelper.key("cc:course", courseId, "lessons"));
                if (CollectionUtils.isEmpty(lessonIds)) {
                    lessonIds=lessonService.queryLessonIdsByCourseId(courseId);
                }
                // 根据课程ID，获取小节列表
                Set<String> lvIds = jedis.smembers(JedisHelper.key("cc:course", courseId, "lvs"));
                if (CollectionUtils.isEmpty(lvIds)) {
                    lvIds=lessonVideoService.queryLessonVideoIdsByCourseId(courseId);
                }
                //需要查询的字段信息
                String[] chapterFields=new String[]{"name", "rank", "limitDay","isPass", "id", "description"};
                String[] lessonFields=new String[]{"chapterId", "name", "rank",
                        "videoId", "videoSec", "haveChildren", "knowledgeCardTotal",
                        "courseDataTotal", "id", "introduction"};
                String[] lessonVideoFields=new String[]{"lessonId", "name", "rank", "videoId","videoSec", "id"};
                List<Object> result = courseService.getChapterLessonInfo(jedis, chapterIds, lessonIds, lvIds,
                        chapterFields, lessonFields, lessonVideoFields);
                if (CollectionUtils.isEmpty(result))
                    return;
                List<LessonWebDto> lessons = new ArrayList<LessonWebDto>();
                List<LessonVideoWebDto> lvs = new ArrayList<LessonVideoWebDto>();
                for (int i = 0, len = result.size(); i < len; i++) {
                    Object obj = result.get(i);
                    if (i < chapterIds.size()) {
                        ChapterWebDto chapter = toChapter(obj);
                        if (chapter != null && chapter.getId() != null)
                            chapters.add(chapter);
                    } else if (i < chapterIds.size() + lessonIds.size()) {
                        LessonWebDto lesson = toLesson(obj);
                        if (lesson != null && lesson.getId() != null && lesson.getChapterId() != null)
                            lessons.add(lesson);
                    } else {
                        LessonVideoWebDto lv = toLessonVideo(obj);
                        if (lv != null && lv.getId() != null && lv.getLessonId() != null
                                && lv.getRank() != null)
                            lvs.add(lv);
                    }
                }
                if (CollectionUtils.isEmpty(chapters))
                    return;

                // 组合数据
                // 如果小节列表不为空，将小节写入到节中
                if (!CollectionUtils.isEmpty(lvs)) {
                    // 小节列表排序
                    Collections.sort(lvs, new Comparator<LessonVideoWebDto>() {
                        @Override
                        public int compare(LessonVideoWebDto o1, LessonVideoWebDto o2) {
                            if (o1 == null || o2 == null)
                                return 0;
                            return o1.getRank().compareTo(o2.getRank());
                        }
                    });
                    // 组合数据
                    for (LessonWebDto lesson : lessons) {
                        for (LessonVideoWebDto lv : lvs) {
                            if (lv.getLessonId().equals(lesson.getId())) {
                                if (lesson.getLessonVideos() == null) {
                                    lesson.setLessonVideos(new ArrayList<LessonVideoWebDto>());
                                }
                                lesson.getLessonVideos().add(lv);
                            }
                        }
                    }
                }
                // 如果节列表不为空，将节写入到章中
                if (!CollectionUtils.isEmpty(lessons)) {
                    // 小节列表排序
                    Collections.sort(lessons, new Comparator<LessonWebDto>() {
                        @Override
                        public int compare(LessonWebDto o1, LessonWebDto o2) {
                            if (o1 == null || o2 == null)
                                return 0;
                            return o1.getRank().compareTo(o2.getRank());
                        }
                    });
                    // 组合数据
                    for (ChapterWebDto cwd : chapters) {
                        for (LessonWebDto lesson : lessons) {
                            if (lesson == null || lesson.getId() == null)
                                continue;
                            if (cwd.getId().equals(lesson.getChapterId())) {
                                if (cwd.getLessons() == null)
                                    cwd.setLessons(new ArrayList<LessonWebDto>());
                                cwd.getLessons().add(lesson);
                            }
                        }
                    }
                }
            }
        });
        if (!CollectionUtils.isEmpty(chapters)) {
            Collections.sort(chapters, new Comparator<ChapterWebDto>() {

                @Override
                public int compare(ChapterWebDto o1, ChapterWebDto o2) {
                    if (o1 == null || o2 == null) {
                        return 0;
                    }
                    return o1.getRank().compareTo(o2.getRank());
                }

            });
            result.setResult(chapters);
        }

        return result;

    }
    
    @Override
    public RemoteResult<List<ChapterWebDto>> queryAllChapterInfos(final long courseId) {


        RemoteResult<List<ChapterWebDto>> result = new RemoteResult<List<ChapterWebDto>>();
        // 参考com.zhihuishu.micro.course.openapi.cc.impl.ChapterLessonOpenServiceImpl#queryChapterBasicInfos逻辑
        final List<ChapterWebDto> chapters = new ArrayList<ChapterWebDto>();
        jedisExecutor.execute( new Handler() {
            @Override
            public void handle(Jedis jedis) {
                // 根据课程ID，获取章列表
                Set<String> chapterIds = jedis.smembers(JedisHelper.key("cc:course", courseId, "chapters:all"));
                if (CollectionUtils.isEmpty(chapterIds)) {
                    chapterIds=chapterService.queryChapterIdsByCourseIdAndAddToCache(courseId);
                }
                // 根据课程ID，获取节列表
                Set<String> lessonIds = jedis.smembers(JedisHelper.key("cc:course", courseId, "lessons"));
                if (CollectionUtils.isEmpty(lessonIds)) {
                    lessonIds=lessonService.queryLessonIdsByCourseId(courseId);
                }
                // 根据课程ID，获取小节列表
                Set<String> lvIds = jedis.smembers(JedisHelper.key("cc:course", courseId, "lvs"));
                if (CollectionUtils.isEmpty(lvIds)) {
                    lvIds=lessonVideoService.queryLessonVideoIdsByCourseId(courseId);
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("查询到章ids为{}",chapterIds);
                    logger.debug("查询到节ids为{}",lessonIds);
                    logger.debug("查询到小节ids为{}",lvIds);
                }
                // 使用管道获取数据
                //需要查询的字段信息
                String[] chapterFields=new String[]{"name", "rank", "limitDay","isPass", "id", "description"};
                String[] lessonFields=new String[]{"chapterId", "name", "rank",
                        "videoId", "videoSec", "haveChildren", "knowledgeCardTotal",
                        "courseDataTotal", "id", "introduction"};
                String[] lessonVideoFields=new String[]{"lessonId", "name", "rank", "videoId","videoSec", "id"};
                List<Object> result = courseService.getChapterLessonInfo(jedis, chapterIds, lessonIds, lvIds,
                        chapterFields, lessonFields, lessonVideoFields);
                if (CollectionUtils.isEmpty(result)){
                    return;
                }
                List<LessonWebDto> lessons = new ArrayList<LessonWebDto>();
                List<LessonVideoWebDto> lvs = new ArrayList<LessonVideoWebDto>();
                for (int i = 0, len = result.size(); i < len; i++) {
                    Object obj = result.get(i);
                    if (i < chapterIds.size()) {
                        ChapterWebDto chapter = toAllChapter(obj);
                        if (chapter != null && chapter.getId() != null)
                            chapters.add(chapter);
                    } else if (i < chapterIds.size() + lessonIds.size()) {
                        LessonWebDto lesson = toLesson(obj);
                        if (lesson != null && lesson.getId() != null && lesson.getChapterId() != null)
                            lessons.add(lesson);
                    } else {
                        LessonVideoWebDto lv = toLessonVideo(obj);
                        if (lv != null && lv.getId() != null && lv.getLessonId() != null
                                && lv.getRank() != null)
                            lvs.add(lv);
                    }
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("查询到章数据为{}",chapters);
                    logger.debug("查询到节数据为{}",lessons);
                    logger.debug("查询到小节的数据为{}",lvs);
                }
                if (CollectionUtils.isEmpty(chapters))
                    return;

                // 组合数据
                // 如果小节列表不为空，将小节写入到节中
                if (!CollectionUtils.isEmpty(lvs)) {
                    // 小节列表排序
                    Collections.sort(lvs, new Comparator<LessonVideoWebDto>() {
                        @Override
                        public int compare(LessonVideoWebDto o1, LessonVideoWebDto o2) {
                            if (o1 == null || o2 == null)
                                return 0;
                            return o1.getRank().compareTo(o2.getRank());
                        }
                    });
                    // 组合数据
                    for (LessonWebDto lesson : lessons) {
                        for (LessonVideoWebDto lv : lvs) {
                            if (lv.getLessonId().equals(lesson.getId())) {
                                if (lesson.getLessonVideos() == null) {
                                    lesson.setLessonVideos(new ArrayList<LessonVideoWebDto>());
                                }
                                lesson.getLessonVideos().add(lv);
                            }
                        }
                    }
                }
                // 如果节列表不为空，将节写入到章中
                if (!CollectionUtils.isEmpty(lessons)) {
                    // 小节列表排序
                    Collections.sort(lessons, new Comparator<LessonWebDto>() {
                        @Override
                        public int compare(LessonWebDto o1, LessonWebDto o2) {
                            if (o1 == null || o2 == null)
                                return 0;
                            return o1.getRank().compareTo(o2.getRank());
                        }
                    });
                    // 组合数据
                    for (ChapterWebDto cwd : chapters) {
                        for (LessonWebDto lesson : lessons) {
                            if (lesson == null || lesson.getId() == null)
                                continue;
                            if (cwd.getId().equals(lesson.getChapterId())) {
                                if (cwd.getLessons() == null)
                                    cwd.setLessons(new ArrayList<LessonWebDto>());
                                cwd.getLessons().add(lesson);
                            }
                        }
                    }
                }
            }

            
        });
        if (!CollectionUtils.isEmpty(chapters)) {
            Collections.sort(chapters, new Comparator<ChapterWebDto>() {

                @Override
                public int compare(ChapterWebDto o1, ChapterWebDto o2) {
                    if (o1 == null || o2 == null) {
                        return 0;
                    }
                    return o1.getRank().compareTo(o2.getRank());
                }

            });
            result.setResult(chapters);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("查询到课程{}章节结构最终数据为{}",courseId,result.getResult());
        }

        return result;
    }

    /**
     * 从Redis获取的数据转换为章对象：[古代上海人事物, 1, 10, 1, 1121]
     *  2, 2, null, 0, 123867, null
     * @param obj
     * @return
     */
    private ChapterWebDto toChapter(Object obj) {
        if (obj == null)
            return null;
        @SuppressWarnings("unchecked")
        List<String> list = (List<String>) obj;
        // 判断是否通过，未通过，则认为章不存在(不对外公布)
        if (list.get(3) == null || NumberUtils.toInt(list.get(3)) == 0)
            return null;
        ChapterWebDto cwd = new ChapterWebDto();
        if (list.get(0) != null)
            cwd.setName(list.get(0).toString());
        if (list.get(1) != null)
            cwd.setRank(NumberUtils.toInt(list.get(1).toString()));
        if (list.get(2) != null)
            cwd.setLimitDay(NumberUtils.toInt(list.get(2).toString()));
        if (list.get(4) != null)
            cwd.setId(NumberUtils.toInt(list.get(4).toString()));
        if (list.get(5) != null) {
            cwd.setDescription(list.get(5));
        }
        return cwd;
    }
    private ChapterWebDto toAllChapter(Object obj) {
        if (obj == null)
            return null;
        @SuppressWarnings("unchecked")
        List<String> list = (List<String>) obj;
        // 判断是否通过，未通过，则认为章不存在(不对外公布)
        /*if (list.get(3) == null || NumberUtils.toInt(list.get(3)) == 0)
            return null;*/
        ChapterWebDto cwd = new ChapterWebDto();
        if (list.get(0) != null)
            cwd.setName(list.get(0).toString());
        if (list.get(1) != null)
            cwd.setRank(NumberUtils.toInt(list.get(1).toString()));
        if (list.get(2) != null)
            cwd.setLimitDay(NumberUtils.toInt(list.get(2).toString()));
        if (list.get(4) != null)
            cwd.setId(NumberUtils.toInt(list.get(4).toString()));
        if (list.get(5) != null) {
            cwd.setDescription(list.get(5));
        }
        return cwd;
    }

    private LessonWebDto toLesson(Object obj) {
        if (obj == null)
            return null;
        @SuppressWarnings("unchecked")
        List<String> list = (List<String>) obj;
        LessonWebDto lwd = new LessonWebDto();
        if (list.get(0) != null)
            lwd.setChapterId(NumberUtils.toInt(list.get(0).toString()));
        if (list.get(1) != null)
            lwd.setName(list.get(1).toString());
        if (list.get(2) != null)
            lwd.setRank(NumberUtils.toInt(list.get(2).toString()));
        if (list.get(3) != null){
            lwd.setVideoId(NumberUtils.toLong(list.get(3).toString()));
        }else {
            lwd.setVideoId(0L);//为与缓存保持一致
        }
        if (list.get(4) != null){
            lwd.setVideoSec(NumberUtils.toInt(list.get(4).toString()));
        }else {
            lwd.setVideoSec(0);//为与缓存保持一致
        }
        if (list.get(5) != null)
            lwd.setHaveChildren(NumberUtils.toInt(list.get(5).toString()) > 0 ? 1 : 0);
        if (list.get(6) != null)
            lwd.setKnowledgeCardTotal(NumberUtils.toInt(list.get(6).toString()));
        if (list.get(7) != null)
            lwd.setCourseDataTotal(NumberUtils.toInt(list.get(7).toString()));
        if (list.get(8) != null)
            lwd.setId(NumberUtils.toInt(list.get(8).toString()));
        if (list.get(9) != null) {
            lwd.setIntroduction(list.get(9));
        }
        return lwd;
    }

    private LessonVideoWebDto toLessonVideo(Object obj) {
        if (obj == null)
            return null;
        @SuppressWarnings("unchecked")
        List<String> list = (List<String>) obj;
        LessonVideoWebDto lvw = new LessonVideoWebDto();
        if (list.get(0) != null)
            lvw.setLessonId(NumberUtils.toInt(list.get(0).toString()));
        if (list.get(1) != null)
            lvw.setName(list.get(1).toString());
        if (list.get(2) != null)
            lvw.setRank(NumberUtils.toInt(list.get(2).toString()));
        if (list.get(3) != null){
            lvw.setVideoId(NumberUtils.toLong(list.get(3).toString()));
        }else {
            lvw.setVideoId(0L);//为与缓存中保持一致
        }
        if (list.get(4) != null){
            lvw.setVideoSec(NumberUtils.toInt(list.get(4).toString()));
        }else {
            lvw.setVideoSec(0);//为与缓存中保存一致
        }
        if (list.get(5) != null)
            lvw.setId(NumberUtils.toInt(list.get(5).toString()));
        return lvw;
    }

    @Override
    public RemoteResult<Map<String, String>> queryCourseExtentPropByPropName(long courseId,
            CourseExtendPropEumn... courseExtendPropEumns) {
        RemoteResult<Map<String, String>> remoteResult = new RemoteResult<Map<String, String>>();
        try {
            if (courseExtendPropEumns == null || courseExtendPropEumns.length == 0) {
                remoteResult.setResult(new HashMap<String, String>());
                return remoteResult;
            }
            List<String> propList = Lists.newArrayList();
            for (CourseExtendPropEumn courseExtendPropEumn : courseExtendPropEumns) {
                propList.add(StringHelper.underscoreToCamel(courseExtendPropEumn.name()));
            }
            Map<String, String> map = courseService.queryCourseExtentPropByPropNameList(courseId, propList);
            remoteResult.setResult(map);

        } catch (Exception e) {
            remoteResult.setExceptionStack(e);
            remoteResult.setSuccess(false);
        }

        return remoteResult;
    }

    @Override
    public RemoteResult<Void> removeCourseChcheByCourseId(Long courseId) {
        RemoteResult<Void> remoteResult=new RemoteResult<Void>();
        try {
           Assert.notNull(courseId,"课程id不能为空");
           courseService.removeCourseChecheByCourseId(courseId);
        } catch (Exception e) {
            remoteResult.setExceptionStack(e);
            remoteResult.setSuccess(false);
        }
        return remoteResult;
    }
    
    /*@Override
    public RemoteResult<List<CourseOpenDto>> queryCourseInfoByCourseIds(List<Long> courseIds) {
        RemoteResult<List<CourseOpenDto>> remoteResult=new RemoteResult<List<CourseOpenDto>>();
        try {
            List<CourseOpenDto> courseOpenDtos=Lists.newArrayList();
            Assert.notNull(courseIds,"courseIds不能为null");
            Assert.isTrue(courseIds.size()>0);
            List<CourseDto> courseDtos=courseService.queryCourseInfo(courseIds);
            courseOpenDtos=BeanHelper.transTo(courseDtos, CourseOpenDto.class);
            remoteResult.setResult(courseOpenDtos);
        } catch (Exception e) {
            remoteResult.setExceptionStack(e);
            remoteResult.setSuccess(false);
        }
        return remoteResult;
    }*/
    @Override
    public RemoteResult<Void> deleteCourse(Long courseId, long userId) {
        RemoteResult<Void> remoteResult=new RemoteResult<Void>();
        try {
            Assert.notNull(courseId,"删除的课程id不能为空");
            courseService.remove(courseId, userId);
            MDCLoggerUtil.saveLogger(
                    String.format("学堂接口删除课程,courseId=%d,userId=%s", courseId, userId), userId,
                    LoggerCollectionEnum.courseCollection,courseId);
        } catch (Exception e) {
           remoteResult.setExceptionStack(e);
           remoteResult.setSuccess(false);
        }
      
        return remoteResult;
    }

    @Override
    public RemoteResult<Void> deleteCourseInFastWay(Long courseId, long userId) {
        RemoteResult<Void> remoteResult=new RemoteResult<Void>();
        try {
            Assert.notNull(courseId,"删除的课程id不能为空");
            CourseDto courseDto=new CourseDto();
            courseDto.setCourseId(courseId);
            courseDto.setDeleteStatus(1);//当课程下存在招生 删除课程
            courseService.update(courseDto, userId);
            MDCLoggerUtil.saveLogger(
                    String.format("学堂接口快速删除课程,courseId=%d,userId=%s", courseId, userId), userId,
                    LoggerCollectionEnum.courseCollection,courseId);
        } catch (Exception e) {
           remoteResult.setExceptionStack(e);
           remoteResult.setSuccess(false);
        }
       
        return remoteResult;
    }

    @Override
    public RemoteResult<Void> syncCacheMainSpaker(String speaker, long courseId, long userId) {
        RemoteResult<Void> remoteResult=new RemoteResult<Void>();
        try {
            Assert.hasText(speaker,"主讲人参数错误");
            Assert.isTrue(courseId>0,"课程id参数错误");
            Assert.isTrue(userId>0,"用户id参数错误");
            if (logger.isDebugEnabled()) {
                logger.debug("接受到主讲人参数为:{},课程id为{},用户id为{}",speaker,courseId,userId);
            }
            courseService.syncCacheMainSpeaker(speaker,courseId,userId);
        } catch (Exception e) {
            remoteResult.setExceptionStack(e);
            remoteResult.setSuccess(false);
        }
        return remoteResult;
        
    }

  

}

